<meta title="广告列表" />
<div class="p">
    <div class="m-b clearfix">
        <form class="form-inline pull-left" id="form">
            <input autocomplete="off" type="text" class="form-control input-sm" placeholder="广告名" style="width:200px;" name="name" />
            <input autocomplete="off" type="hidden" name="page" id="page" value="1"/>
            <select class="form-control input-sm" s="select" name="valid">
                <option value="">所有状态</option>
                <option value="true">正常</option>
                <option value="false">锁定</option>
            </select>
            <button type="button" class="btn btn-default btn-sm" s-click="$page.node.val(1); $advSpacesGrid.refresh()">查询</button>
        </form>
        <div class="pull-right">
            <div class="btn-group">
                <a href="javascript:;" class="btn btn-primary btn-sm btn-outline"
                   s-click="add()">
                    <i class="fa fa-plus"></i> 新增
                </a>
            </div>
        </div>
    </div>
    <div id="advSpacesGrid"
         s='datac,nda,check'
         s-data="S.get('/api/adv-space/search', $form.node.serialize())">
        <table class="table table-striped table-bordered table-hover table-middle">
            <tr>
                <th>ID</th>
                <th>名称</th>
                <th>code</th>
                <th>创建时间</th>
                <th>状态</th>
                <th class="text-right">操作</th>
            </tr>
            <tbody s="loop" s-data-filter="'results'">
            <tr s-loop-role="empty">
                <td colspan="6">暂无数据</td>
            </tr>
            <tr s-loop-role="row" s-check-role="i" s="datac" class="adv">
                <td name="id"></td>
                <td name="name"></td>
                <td name="code"></td>
                <td name="createTime"></td>
                <td s="tpl">
                    {%if(this.valid){%}
                    <label class="label label-success">正常</label>
                    {%}else{%}
                    <label class="label label-default">锁定</label>
                    {%}%}
                </td>
                <td class="text-right">
                    <input autocomplete="off" type="button" class="btn btn-info btn-outline btn-xs" s-click="advList(this)" value="广告列表" />
                    <input autocomplete="off" type="button" class="btn btn-primary btn-outline btn-xs" s-click="edit(this)" value="编辑" />
                    <input autocomplete="off" type="button" class="btn btn-danger btn-outline btn-xs" s-click="del(this)" value="删除" />
                </td>
            </tr>
            </tbody>
            <tfoot>
            <tr>
                <td colspan="6" class="text-right">
                    共有<span name="total"></span>个数据
                    <ul s="pagination"
                        s-pagination="{action:function(){$page.node.val(this); $advSpacesGrid.refresh()}}"
                        class="pagination pagination-sm">
                    </ul>
                </td>
            </tr>
            </tfoot>
        </table>
    </div>
</div>
<script type="text/javascript">

    function del($this) {
        var data = $this.parent().data()
        S.confirm("确定操作吗？").done(function() {
            S.remove("/api/adv-space/" + data.id).done(function() {
                $advSpacesGrid.refresh();
            })
        })
    }

    function add() {
        S.popupOpen("/adv-space/adv-space-add.html").done(function(rs) {
            rs && $advSpacesGrid.refresh();
        })
    }

    function edit($this) {
        var data = $this.parent().data()
        S.popupOpen("/adv-space/adv-space-add.html", {advSpace: data}).done(function(rs) {
            rs && $advSpacesGrid.refresh();
        })
    }

    function advList($this) {
        var data = $this.parent().data()
        S.popupOpen("/adv-space/adv-space-item-list.html", {advSpaceId: data.id})
    }

</script>